// packageH/stock/_module_components/goods_item/goods_item.js
Component({
  properties: {
    data: {
      type: Object,
      default: {},
    },
    show_price_flag:{
      type:Boolean,
      value:false,
    },
    show_price:{
      type:Boolean,
      value:false,
    },
    index:{
      type:Number,
      value: null
    },
    idTag: {
      type: String,
      value: 'id'
    },
    isCart: {
      type: Boolean,
      value: false
    },
  },
  data: {
    timer: null
  },
  methods: {
    showGoodDetail() {
      this.triggerEvent("show", { id: this.data.data[this.data.idTag], index: this.data.index });
    },
    addCart() {
      console.log("addCart=============")
      if (this.data.timer) clearTimeout(this.data.timer); //防抖
      this.data.timer = setTimeout(() => {
        this.triggerEvent("add", { id: this.data.data[this.data.idTag], isSpecs: this.data.data.has_option, index: this.data.index });
      }, 500);
    },
    onchange(event) {
      if (this.data.timer) clearTimeout(this.data.timer); //防抖
      this.data.timer = setTimeout(() => {
        this.triggerEvent("change", { id: this.data.data[this.data.idTag], isSpecs: this.data.data.has_option, index: this.data.index, num: event.detail, cartId: this.data.data.card_id });
      }, 500);
    }
  }
});
